package com.dmap.admin.constants;

import java.util.Map;
import java.util.WeakHashMap;

/**
 * \* User: silent
 * \* Date: 27/11/17 Time: 09:57
 * \* Description: 通用的系统常量
 * \
 */
public class AdminConstant {
    private AdminConstant() {
    }

    /**
     * admin模块错误有15开头
     */

    public static final Integer RESPONSE_ACCOUNT_EXIST_ERROR_CODE = 15001;
    public static final String RESPONSE_ACCOUNT_EXIST_ERROR_MSG = "存在相同用户";

    public static final Integer RESPONSE_LOGIN_ERROR_CODE = 15002;
    public static final String RESPONSE_LOGIN_ERROR_MSG = "用户账号和密码错误, 登录错误次数达到五次将封锁账号";
    public static final Integer RESPONSE_OPERATE_ERROR_CODE = 15003;
    public static final String RESPONSE_OPERATE_ERROR_MSG = "不可执行此操作";
    public static final Integer RESPONSE_COMPANY_ERROR_CODE = 15004;
    public static final String RESPONSE_COMPANY_ERROR_MSG = "公司编号、名称和管理员id需唯一";
    public static final Integer RESPONSE_USER_ERROR_CODE = 15005;
    public static final String RESPONSE_USER_ERROR_MSG = "用户账号或手机号已存在";
    public static final Integer RESPONSE_LOGIN_V2_ACCOUNT_ERROR_CODE = 15006;
    public static final String RESPONSE_LOGIN_V2_ACCOUNT_ERROR_MSG = "用户账号或手机号错误";
    public static final Integer RESPONSE_LOGIN_V2_PW_ERROR_CODE = 15007;
    public static final String RESPONSE_LOGIN_V2_PW_ERROR_MSG = "登陆密码错误, 登录错误次数达到五次将封锁账号";
    public static final Integer RESPONSE_DEPARTMENT_EXIST_ERROR_CODE = 15008;
    public static final String RESPONSE_DEPARTMENT_EXIST_ERROR_MSG = "在同一个公司中部门名称唯一";
    public static final Integer RESPONSE_DELETE_MEMBER_NUM_NOT_0_ERROR_CODE = 15009;
    public static final String RESPONSE_DELETE_MEMBER_NUM_NOT_0_ERROR_MSG = " 部门成员不为0.(删除功能只有当部门成员为0时，才可以删除)";
    public static final Integer RESPONSE_CODE_SEND_ERROR_CODE = 15010;
    public static final String RESPONSE_CODE_SEND_ERROR_MSG = "验证码发送失败";
    public static final Integer RESPONSE_LOGIN_WRONG_NUM_ERROR_CODE = 15011;
    public static final String RESPONSE_LOGIN_WRONG_NUM_ERROR_MSG = "登录错误次数已达到五次，账号已被封锁，请联系管理员";
    public static final Integer RESPONSE_APP_UNIQUE_ERROR_CODE = 15012;
    public static final String RESPONSE_APP_UNIQUE_ERROR_MSG = "App编号和App名称需唯一";
    public static final Integer RESPONSE_DEVICE_TYPE_UNIQUE_ERROR_CODE = 15013;
    public static final String RESPONSE_DEVICE_TYPE_UNIQUE_ERROR_MSG = "设备类型编号和设备类型名称需唯一";
    public static final Integer RESPONSE_DEVICE_UNIQUE_ERROR_CODE = 15014;
    public static final String RESPONSE_DEVICE_UNIQUE_ERROR_MSG = "设备固件编号和设备名称需唯一";
    public static final Integer RESPONSE_DEVICE_PROJECT_UNIQUE_ERROR_CODE = 15015;
    public static final String RESPONSE_DEVICE_PROJECT_UNIQUE_ERROR_MSG = "同一个固件只能分配给一家公司";
    public static final Integer RESPONSE_CODE_VALIDATE_ERROR_CODE = 15016;
    public static final String RESPONSE_CODE_VALIDATE_ERROR_MSG = "手机号错误或者验证码已失效（验证码有效期10分钟）";
    public static final Integer RESPONSE_CODE_WRONG_ERROR_CODE = 15017;
    public static final String RESPONSE_CODE_WRONG_ERROR_MSG = "验证码错误";
    public static final Integer RESPONSE_USER_STATUS_ERROR_CODE = 15018;
    public static final String RESPONSE_USER_STATUS_ERROR_MSG = "没有启用的用户，不能登录系统";
    public static final Integer RESPONSE_COMPANY_STATUS_ERROR_CODE = 15019;
    public static final String RESPONSE_COMPANY_STATUS_ERROR_MSG = "所属公司已禁用，公司所有成员不能登录本系统";
    public static final Integer RESPONSE_APP_PROJECT_UNIQUE_ERROR_CODE = 15020;
    public static final String RESPONSE_APP_PROJECT_UNIQUE_ERROR_MSG = "同一个App只能分配给一家公司";

    public static final Integer DEFAULT_PAGE_SIZE = 1000;

    public static final Integer MAX_LOGIN_WRONG_NUM = 4;//登陆错误次数大于4次

    public static final String SUPER_ADMIN_USER = "superadmin";
    public static final String SUPER_ADMIN_ROLE = "超级管理员";

    public static final Integer NO_CHILD = 0;//标记是否有子菜单项 0-无子菜单，1-有子菜单
    public static final Integer HAS_CHILD = 1;//标记是否有子菜单项 0-无子菜单，1-有子菜单

    public static final Integer NORMAL_STATUS = 1;//状态：1正常，2禁用
    public static final Integer FORBID_STATUS = 2;

    public static final Integer COMPANY_TYPE_HEAD = 1;//公司类型：1.总公司， 2分公司
    public static final Integer COMPANY_TYPE_BRANCH = 2;

    public static final Integer USER_TYPE_COMPANY_ADMIN = 1;//用户类型：1.公司管理员，2.部门管理员，3.普通用户
    public static final Integer USER_TYPE_DEPARTMENT_ADMIN = 2;
    public static final Integer USER_TYPE_NORMAL = 3;

    public static final Integer DELETE_STATUS_NORMAL = 1; //删除状态: 1正常，2已删除
    public static final Integer DELETE_STATUS_DELETED = 2;

    public static final String CREATE_TIME = " create_time";//创建时间
    public static final String UPDATE_TIME = " update_time";//最后更新时间
    public static final Integer ORDER_BY_ASC = 0; //0 asc正序, 1 desc倒序
    public static final Integer ORDER_BY_DESC = 1;
    public static final String DESC = " desc";

    public static final String SORT_BY_LAST_LOGIN_TIME = "lastLoginTime";//最后登陆时间
    public static final String SORT_BY_MEMBER_NUM = "memberNum";//成员数量，部门排序用

    private static final Map<String, String> orderByClauseMap = new WeakHashMap<>();

    static {
        orderByClauseMap.put("account", " account");//用户账号
        orderByClauseMap.put("name", " name");//名称
        orderByClauseMap.put("createTime", CREATE_TIME);//创建时间
        orderByClauseMap.put("updateTime", UPDATE_TIME);//最后更新时间
        orderByClauseMap.put("status", " status");//是否启用,状态：1正常，2禁用
        orderByClauseMap.put("number", " number");//公司编号
        orderByClauseMap.put("administratorAccount", " administrator_account");//管理员账号
        orderByClauseMap.put("companyPhone", " company_phone");//公司联系电话
        orderByClauseMap.put("projectId", " project_id");//APP编号
        orderByClauseMap.put("projectName", " project_name");//APP名称
        orderByClauseMap.put("companyName", " company_name");//所属公司名称
        orderByClauseMap.put("firmware", " firmware");//设备固件编号
        orderByClauseMap.put("deviceName", " device_name");//设备名称
        orderByClauseMap.put("handphone", " handphone");//手机号
        orderByClauseMap.put("email", " email");//邮箱
        orderByClauseMap.put("typeNumber", " type_number");//类型编号
        orderByClauseMap.put("typeName", " type_name");//类型名称
        orderByClauseMap.put("editorAccount", " editor_account");//最后更新者账号
    }

    private static final Map<Integer, String> orderByClauseSequenceMap = new WeakHashMap<>();

    static {
        orderByClauseSequenceMap.put(0, " asc");//0 asc正序, 1 desc倒序
        orderByClauseSequenceMap.put(1, DESC);
    }

    public static Map<String, String> getOrderByClauseMap() {
        return orderByClauseMap;
    }

    public static Map<Integer, String> getOrderByClauseSequenceMap() {
        return orderByClauseSequenceMap;
    }

    //公司信息前缀相关定义
    public static final String CACHE_COMPANY_INFO_CODE = "companyInfo001"; //公司信息存储key前缀
    public static final String CACHE_IDENTIFY_PHONE_CODE = "identify001"; //短信验证码key前缀 + phone
    public static final String CACHE_COMPANY_PROJECT_CODE = "dmapadmin09"; //公司所属app key前缀 + companyId

    //缓存时间定义
    public static final int CACHE_SECONDS_60 = 60; //redis有效期（S）
    public static final int CACHE_SECONDS_600 = 60 * 10; //redis有效期（S）
}
